<template>
  <!-- 循环渲染数据 -->
  <div>
    <ul>
      <li v-for="(item, index) in list" :key="index">
        {{ item.name }} {{ item.nickname }}
        <button @click="del(item.id)">删除当前数据</button>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: [
        { id: 2, name: "宋江", nickname: "及时雨" },
        { id: 3, name: "吴用", nickname: "智多星" },
        { id: 5, name: "林冲", nickname: "豹子头" },
        { id: 7, name: "花荣", nickname: "小李广" },
      ],
    };
  },
  methods: {
    del(id) {
      // filter 把符合条件的数据筛选出来，形成一个新数组
      this.list = this.list.filter((item) => item.id != id);
    },
  },
};
</script>

<style>
</style>